package com.bytech.common.biz.enums.article;

import com.bytech.common.utils.StringUtils;
import com.google.common.collect.ImmutableList;
import lombok.Getter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Zhao
 * @Create 2021/8/11 22:34
 */
@Getter
public enum ArticleStatusEnum {

    UNKNOWN("unknown", "未知"),
    CREATED("created", "已创建"),
    PUBLISHED("published", "已发布"),
    DELETED("deleted", "已删除"),
    ;

    private final String value;
    private final String desc;

    ArticleStatusEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    private static final Map<String, ArticleStatusEnum> map = new HashMap<>(ArticleStatusEnum.values().length);

    static {
        for (ArticleStatusEnum e : ArticleStatusEnum.values()) {
            map.put(e.value, e);
        }
    }

    public static ArticleStatusEnum of(String state) {
        if (StringUtils.isBlank(state)) {
            return UNKNOWN;
        }
        return map.get(state) == null ? UNKNOWN : map.get(state);
    }

    public static List<ArticleStatusEnum> validValues() {
        return ImmutableList.of(CREATED, PUBLISHED, DELETED);
    }
}
